package com.shuaiche.yeguan.wxapi;

import android.os.Bundle;

import com.facebook.react.ReactActivity;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.modules.core.DeviceEventManagerModule;
import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;

public class WXPayEntryActivity extends ReactActivity implements IWXAPIEventHandler {


    private IWXAPI api;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        api = WXAPIFactory.createWXAPI(this, "wx6ffad2eebf675d61");
        api.handleIntent(getIntent(), this);
    }


    @Override
    public void onReq(BaseReq req) {

    }

    @Override
    public void onResp(BaseResp resp) {
        try {
            ReactContext reactContext= getReactNativeHost().getReactInstanceManager().getCurrentReactContext();
            if (reactContext == null) {
                return;
            }
            // WritableMap 对应 JS 中的 Object
            WritableMap event = Arguments.createMap();
            //传递的参数
            event.putString("wxPayCode",resp.errCode+"");

            reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit("wxPayCode",event);
        }catch (Exception e){

        }
        finish();

    }
}
